package com.my.mall.client.order.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.my.mall.client.order.dto.OrderInfoClientDTO;
import com.my.mall.client.order.service.OrderClientService;
import com.my.mall.client.order.vo.OrderClientVo;
import com.my.mall.common.R;

@Controller
@RequestMapping("client/orderInfo")
public class OrderClientController {
	@Autowired
	OrderClientService orderClientService;

	@RequestMapping("save")
	@ResponseBody
	public R save(@RequestBody OrderInfoClientDTO orderDTO) {
		Map<String, Object> map = new HashMap<>();
		String orderNumber = String.valueOf(System.currentTimeMillis());
		orderDTO.setOrderStatus(0);
		orderDTO.setOrderTime(new Date());
		orderDTO.setOrderNumber(orderNumber);
		int result = orderClientService.saveOrderInfo(orderDTO);
		if (result == 1) {
			map.put("orderNumber",orderNumber);
			return R.ok(map);
		}
		else
			return R.error("系统故障！");
	}
	
	@RequestMapping("getOrderInfo/{orderId}")
	@ResponseBody
	public R getOrderInfo(@PathVariable("orderId") int id) {
		Map<String, Object> map = new HashMap<>();
		OrderClientVo orderInfoVo = orderClientService.getOrderInfo(id);
		if(orderInfoVo != null) {
			map.put("orderInfoVo", orderInfoVo);
			return R.ok(map);
		}
		else
			return R.error("系统故障！");
	}
}